<?php

namespace app\admin\controller;

use app\admin\business\SpecsValue as specsValueBus;
use Exception;

class Specs extends AdminBase
{
    public function dialog()
    {
        return view("", [
            "specs" => json_encode(config("specs"))
        ]);
    }
    public function status()
    {
        $id = input("param.id", '', 'intval');
        $status = input("param.status", '', 'intval');
        $data = [
            'id' => $id,
            'status' => $status
        ];
        $validate = new \app\admin\validate\Specs();
        if (!$validate->scene('status')->check($data)) {
            return show(config("status.error"), $validate->getError());
        }
        $specsBus = new specsValueBus();
        try {
            $res = $specsBus->getStatus($data['id'], $data['status']);
        } catch (\Exception $e) {
            throw new Exception("内部异常", $e->getMessage());
        }
        if ($res) {
            return show(config("status.success"), "更新状态成功");
        } else {
            return show(config("status.error"), "更新状态失败");
        }

    }


}